import Vue from 'vue'
import Router from 'vue-router'
import routeMap from './maps'
Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes: routeMap,
  strict: process.env.NODE_ENV !== 'production',
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.documentElement.scrollTop || document.body.scrollTop
      }
      return {
        x: 0,
        y: to.meta.savedPosition || 0
      }
    }
  }
})

router.beforeEach((to, from, next) => {
  next()
})

export default router
